package DBLayer;
import ModelLayer.*;
import static org.junit.Assert.*;
import org.junit.Test;

import java.util.ArrayList;

public class DBMaterialTest {

	@Test
    public void testGetAllMaterials() throws Exception {
        ArrayList<Material> materialList = new ArrayList<Material>();
        DBMaterial dbMat = new DBMaterial();
        materialList = dbMat.getAllMaterials(false);

        if (materialList != null){
            for (Material mat1 : materialList)
                System.out.println("idMaterial " + mat1.getIdMaterial() + "type " + mat1.getType() + "price " + mat1.getAmount());
                                                                                                                                        }
        else fail();
    }

    @Test
    public void testFindMaterialId() throws Exception {
        DBMaterial dbMat = new DBMaterial();
        Material mat = dbMat.findMaterialId("003", false);

        if (mat != null){
            System.out.println("MaterialId has been found");
            System.out.println("IdMaterial : " + mat.getIdMaterial() + " price : " + mat.getPrice());
        }
        else fail();
    }




	
	@Test
	public void testInsertMaterial() throws Exception
	{
		DBMaterial DBMat = new DBMaterial();
		String idMaterial = "1";
		String type = "loftmaling";
		double price = 100.00;
		int shine = 9;
		String colour = "muggrn";
		double amount = 10.00;
		
		Material matObj = new Material(idMaterial, type, price, shine, colour, amount);
		int change = DBMat.insertMaterial(matObj);
		
		if(change == 1)
		{
			System.out.println("The material was created");
		}
		else
		{
			fail();
		}
		
	}

    @Test
	public void testUpdateMaterial() throws Exception
	{
		DBMaterial DBMat = new DBMaterial();
		String idMaterial = null;
		String type = "gulvmaling";
		double price = 10.00;
		int shine = 2;
		String colour = "hamsterbrun";
		double amount = 10.00;
		
		Material matObj = new Material(idMaterial, type, price, shine, colour, amount);
		int change = DBMat.updateMaterial(matObj);
		
		if(change == 1)
		{
			System.out.println("The Material was updated");
		}
		else
		{
			fail();
		}
	}

    @Test
	public void testDeleteMaterial() throws Exception
	{
		String deleteId = "3";
		DBMaterial DBMat = new DBMaterial();
		int change = DBMat.deleteMaterial(deleteId);
		
		if(change == 1)
		{
			System.out.println("The material was deleted");
		}
		else
		{
			fail();
		}
	}
}
